#include "9225.h"

void Write_Cmd(unsigned char cmd)
{
	RS_L;
	DAT=cmd;
    WR_L;
	WR_H;
}

void Write_Data_L(unsigned char Dat)
{
	RS_H;
	DAT=Dat;
	WR_L;
	WR_H;
}

void  Write_Data_U16(unsigned int y)
{
	RS_H;
	DAT=y>>8;
	WR_L;
	WR_H;
	DAT=y;
	WR_L;
	WR_H;
}

void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1)
{
//y0+=32;
//y1+=32;
	Write_Cmd(0x36);Write_Data_U16(x1);
	Write_Cmd(0x37);Write_Data_U16(x0);
	Write_Cmd(0x38);Write_Data_U16(y1);
	Write_Cmd(0x39);Write_Data_U16(y0);
	Write_Cmd(0x20);Write_Data_U16(x0);
	Write_Cmd(0x21);Write_Data_U16(y0);

	Write_Cmd(0x22);
}

void cls(unsigned int bColor)
{
	unsigned char i,j;
	unsigned char DH,DL;

	LCD_SetPos(0,175,0,219);
	RS_H;
	DL=bColor>>8;
	DH=bColor;
	for(i=0;i<176;i++)
	for(j=0;j<220;j++)
	{
		DAT=DL;
		WR_L;WR_H;
		DAT=DH;
		WR_L;WR_H;
	}
}

void tft_int(void)
{
	RD_H;
	CS_L;
    HAL_Delay(130);
    RST_L;
    HAL_Delay(150);
    RST_H;
    HAL_Delay(220);
	Write_Cmd(0xD0);Write_Data_U16(0x0003);
	Write_Cmd(0xEB);Write_Data_U16(0x0B00);
	Write_Cmd(0xEC);Write_Data_U16(0x000F);
	Write_Cmd(0xC7);Write_Data_U16(0x030F);
	Write_Cmd(0x01);Write_Data_U16(0x011C);
	Write_Cmd(0x02);Write_Data_U16(0x0100);
	Write_Cmd(0x03);Write_Data_U16(0x1030);
	Write_Cmd(0x08);Write_Data_U16(0x0808);
	Write_Cmd(0x0F);Write_Data_U16(0x0901);
	HAL_Delay(10);
	Write_Cmd(0x10);Write_Data_U16(0x0000);
	Write_Cmd(0x11);Write_Data_U16(0x1B41); //The register setting is suitable for VCI=2.8V
	HAL_Delay(120);
	Write_Cmd(0x12);Write_Data_U16(0x200E);//The register setting is suitable for VCI=2.8V
	Write_Cmd(0x13);Write_Data_U16(0x0052); //The register setting is suitable for VCI=2.8V
	Write_Cmd(0x14);Write_Data_U16(0x4B5C); //The register setting is suitable for VCI=2.8V
	Write_Cmd(0x30);Write_Data_U16(0x0000);
	Write_Cmd(0x31);Write_Data_U16(0x00DB);
	Write_Cmd(0x32);Write_Data_U16(0x0000);
	Write_Cmd(0x33);Write_Data_U16(0x0000);
	Write_Cmd(0x34);Write_Data_U16(0x00DB);
	Write_Cmd(0x35);Write_Data_U16(0x0000);
	Write_Cmd(0x36);Write_Data_U16(0x00AF);
	Write_Cmd(0x37);Write_Data_U16(0x0000);
	Write_Cmd(0x38);Write_Data_U16(0x00DB);
	Write_Cmd(0x39);Write_Data_U16(0x0000);
	Write_Cmd(0x50);Write_Data_U16(0x0000);
	Write_Cmd(0x51);Write_Data_U16(0x0705);
	Write_Cmd(0x52);Write_Data_U16(0x0C0A);
	Write_Cmd(0x53);Write_Data_U16(0x0401);
	Write_Cmd(0x54);Write_Data_U16(0x040C);
	Write_Cmd(0x55);Write_Data_U16(0x0608);
	Write_Cmd(0x56);Write_Data_U16(0x0000);
	Write_Cmd(0x57);Write_Data_U16(0x0104);
	Write_Cmd(0x58);Write_Data_U16(0x0E06);
	Write_Cmd(0x59);Write_Data_U16(0x060E);;
	Write_Cmd(0x20);Write_Data_U16(0x0000);
	Write_Cmd(0x21);Write_Data_U16(0x0000);
	Write_Cmd(0x07);Write_Data_U16(0x1017);

    Write_Cmd(0x21);Write_Data_U16(0x0000);
    Write_Cmd(0x22);
    HAL_Delay(15);

}


